package com.sunsharing.common.config;

import com.sunsharing.common.Constant;
import com.sunsharing.common.URL;
import com.sunsharing.common.utils.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * User: criss
 * Date: 13-4-5
 * Time: 上午11:30
 * To change this template use File | Settings | File Templates.
 */
public class ChannelModel implements Serializable {
    public String name;
    public String type;
    public String port;
    public NodeModel nodeModel;
    //mem
    public String mailboxType;
    //文件交换的监听
    public String lisen;

    public URL getURL()
    {
//       return URL.valueOf(type+"://"+nodeModel.domain+"."+nodeModel.ip+":"+port+"?"+ Constant.URL_PAR_MY_NODE_ID+"="+Config.getInstance().getNodeId()+"&"+
//       Constant.URL_PAR_CHANNEL_NAME +"="+name);

        Map par = new HashMap();
        par.put(Constant.URL_PAR_MY_NODE_ID,Config.getInstance().getNodeId());
        par.put(Constant.URL_PAR_CHANNEL_NAME,name);
        if(!StringUtils.isBlank(mailboxType)) {
            par.put(Constant.URL_PAR_MAILBOX,mailboxType);
        }
        if(!StringUtils.isBlank(lisen))
        {
            par.put(Constant.URL_PAR_FILE_LISEN,lisen);
        }
        if(!StringUtils.isBlank(nodeModel.rootpath))
        {
            par.put(Constant.URL_PAR_ROOT_FILE_PATH,nodeModel.rootpath);
        }

        if(StringUtils.isBlank(port))
        {
            port = "0";
        }
        URL url= new URL(type,nodeModel.domain,nodeModel.ip,new Integer(port),"",par);
        return url;
    }

}
